package com.qingke.oo.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Staff {
	private String id;
	private String name;
	private int age;
	private List<Staff> employee = new ArrayList<Staff>();
	private Staff employer;
	private boolean isBoss;
	
	public Staff(String id,String name,int age,Staff employer,boolean isBoss){
		this.id = id;
		this.name = name;
		this.age = age;
		this.employer = employer;
		this.isBoss = isBoss;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public List<Staff> getEmployee() {
		return employee;
	}
	public void addEmployee(Staff employee) {
		this.employee.add(employee);
	}
	public Staff getEmployer() {
		return employer;
	}
	public void setEmployer(Staff employer) {
		this.employer = employer;
	}
	public boolean isBoss() {
		return isBoss;
	}
	public void setBoss(boolean isBoss) {
		this.isBoss = isBoss;
	}
	@Override
	public String toString() {
		if(this.employee.size() != 0){
		return "Staff [id=" + id + ", name=" + name + ", age=" + age  + ", employer="
				+ employer + "]";
		}else{
		return "Staff [id=" + id + ", name=" + name + ", age=" + age + ", employee= null" + ", employer="
		+ employer + "]";
		}
	}
	
	
	public static void main(String []args){
		Map<String,Staff> staffMap = new HashMap<String,Staff>();
		Staff one = new Staff("001", "Mike", 30, null, true);
		Staff two = new Staff("002", "Mike", 30, one, false);
		Staff three = new Staff("003", "Mike", 30, two, false);
		Staff four = new Staff("004", "Mike", 30, null, true);
		Staff five = new Staff("005", "Mike", 30, four, false);
		Staff six = new Staff("006", "Mike", 30, five, false);
		Staff seven = new Staff("007", "Mike", 30, five, false);
		Staff eight = new Staff("008", "Mike", 30, five, false);
		one.addEmployee(two);
		two.addEmployee(three);
		four.addEmployee(five);
		five.addEmployee(six);
		five.addEmployee(seven);
		five.addEmployee(eight);
		staffMap.put("001", one);
		staffMap.put("002", two);
		staffMap.put("003", three);
		staffMap.put("004", four);
		staffMap.put("005", five);
		staffMap.put("006", six);
		staffMap.put("007", seven);
		staffMap.put("008", eight);
		
		for(Map.Entry<String, Staff> entry:staffMap.entrySet()){
			if(entry.getValue().isBoss){
				printAll(entry.getValue(),0);
			}
		}
	}
	public static void printAll(Staff staff,int count){
		count++;
		
			System.out.println(staff);
			if(staff.getEmployee().size() > 0){
				int temp ;
				for(int i = 0;i<staff.getEmployee().size();i++){
					temp = count;
					while(temp > 0){
						System.out.print("\t");
						temp--;
					}
					printAll(staff.getEmployee().get(i),count);
				}
			}
		return;
	} 
	
}
